<template>
  <div>
    <div class="layout">
      <div class="register-container">
        <Subtitle :text="$t('userForm.title3')"/>
        <div>
          <IntelInput
              :label="$t('userForm.emergencyContactLastName')"
              v-model="form.emergencyContactLastName"
              :placeholder="$t('userForm.emergencyContactLastName')"
              class="register-input"
          />
          <IntelInput
              :label="$t('userForm.emergencyContactFirstName')"
              v-model="form.emergencyContactFirstName"
              :placeholder="$t('userForm.emergencyContactFirstName')"
              class="register-input"
          />
          <IntelInput
              :label="$t('userForm.emergencyContactPhoneNumber')"
              v-model="form.emergencyContactPhoneNumber"
              :placeholder="$t('userForm.emergencyContactPhoneNumber')"
              class="register-input"
          />
          <IntelInput
              :label="$t('userForm.emergencyContactAlternatePhoneNumber')"
              v-model="form.emergencyContactAlternatePhoneNumber"
              :placeholder="$t('userForm.emergencyContactAlternatePhoneNumber')"
              class="register-input"
          />
          <IntelInput
              :label="$t('userForm.relationToInvitee')"
              v-model="form.relationToInvitee"
              :placeholder="$t('userForm.relationToInvitee')"
              class="register-input"
          />
          <div class="check-group">
            <div class="label">{{ $t('userForm.allergiesOrOtherMedicalRestrictions') }}</div>
            <div class="check-button">
              <input type="radio" id="yes" :value="$t('dictionary.yesOrNo[0]')" v-model="form.allergiesMedicalRestrictionsItem">
              <label for="yes">{{ $t('dictionary.yesOrNo[0]') }}</label>
              <div class="divider-space"></div>
              <input type="radio" id="no" :value="$t('dictionary.yesOrNo[1]')" v-model="form.allergiesMedicalRestrictionsItem">
              <label for="no">{{ $t('dictionary.yesOrNo[1]') }}</label>
            </div>
            <textarea
                v-if="form.allergiesMedicalRestrictionsItem === $t('dictionary.yesOrNo[0]')"
                v-model="form.allergiesMedicalRestrictionsDetails"
                rows="7"
                :placeholder="$t('userForm.pleaseListHere')"
            ></textarea>
          </div>
          <div class="check-group">
            <div class="label">{{ $t('userForm.doYouHaveAnyDietaryRestrictions') }}</div>
            <div class="check-button">
              <template v-for="(item, index) in $t('dictionary.dietary')">
                <input
                    type="radio"
                    :id="index"
                    :value="$t(`dictionary.dietary[${index}]`)"
                    v-model="form.dietaryRestrictionsItem"
                >
                <label :for="index">{{ $t(`dictionary.dietary[${index}]`) }}</label>
                <div class="divider-space"></div>
              </template>
            </div>
            <textarea
                v-if="form.dietaryRestrictionsItem === $t('dictionary.dietary[3]')"
                v-model="form.dietaryRestrictionsDetails"
                rows="7"
                :placeholder="$t('userForm.pleaseListHere')"
            ></textarea>
          </div>
          <div class="input-group">
          <div class="primary-button" @click="handleSubmit">{{ $t('userForm.buttonSave') }}</div>
<!--            <div class="divider-space"></div>-->
<!--            <div class="ghost-button" @click="handleReturn">{{ $t('userForm.buttonReturn') }}</div>-->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import IntelInput from "../../components/common/IntelInput";
import IntelSelect from "../../components/common/IntelSelect";
import Subtitle from "../../components/common/Subtitle";
import {getUserInfo, getUserInfoAuto, register, updateUserInfo, validEmail} from "../../api/service";

export default {
  name: "faq",
  components: {
    IntelInput,
    IntelSelect,
    Subtitle
  },
  data: function () {
    return {
      form: {
        emergencyContactFirstName: "",
        emergencyContactLastName: "",
        emergencyContactPhoneNumber: "",
        emergencyContactAlternatePhoneNumber: "",
        relationToInvitee: "",
        allergiesMedicalRestrictionsDetails: "",
        allergiesMedicalRestrictionsItem: '',
        dietaryRestrictionsItem: '否',
        dietaryRestrictionsDetails: ''
      }
    }
  },
  mounted() {
    const user = JSON.parse(localStorage.overnight_userInfo)
    this.form = {
      id: user.id,
      businessEmailAddress: user.businessEmailAddress,
      emergencyContactFirstName: user.emergencyContactFirstName,
      emergencyContactLastName: user.emergencyContactLastName,
      emergencyContactPhoneNumber: user.emergencyContactPhoneNumber,
      emergencyContactAlternatePhoneNumber: user.emergencyContactAlternatePhoneNumber,
      relationToInvitee: user.relationToInvitee,
      allergiesMedicalRestrictionsItem: user.allergiesMedicalRestrictionsItem,
      allergiesMedicalRestrictionsDetails: user.allergiesMedicalRestrictionsDetails,
      dietaryRestrictionsItem: user.dietaryRestrictionsItem || '否',
      dietaryRestrictionsDetails: user.dietaryRestrictionsDetails
    }
  },
  methods: {
    handleReturn() {
      this.$router.push({
        path: this.$i18n.path('generalInfo')
      })
    },

    handleSubmit() {
      const that = this
      updateUserInfo(this.form).then(res => {
        console.log(res)
        if (res.data) {
          getUserInfoAuto()
          that.next()
        }
      })
    },
    next () {
      this.$router.push({
        path: this.$i18n.path('userInfo')
      })
    }
  }
}
</script>

<style scoped>
.register-container {
  width: 800px;
  padding-top: 60px;
  padding-left: 120px;
  padding-bottom: 120px;
}

.create-text {
  padding-top: 0px;
}

.create-text .title {
  font-weight: bold;
  font-size: 20px;
  color: #0068B5;
  padding-bottom: 18px;
}

.create-text .desc {
  font-size: 14px;
  color: #999999;
}

.create-text .desc a {
  color: #0068B5;
  text-decoration: none;
}

.form {
  padding-top: 24px;
}

.register-input, .check-group {
  margin-top: 16px;
  width: 100%;
}

.input-group {
  width: 100%;
  display: flex;
}

.divider-space {
  width: 32px;
  height: 30px;
  display: inline-block;
}



.primary-button {
  width: 146px;
  height: 36px;
  color: white;
  font-size: 14px;
  text-align: center;
  line-height: 36px;
  background: #0068B5;
  cursor: pointer;
  margin-top: 16px;
}
.ghost-button {
  width: 146px;
  height: 36px;
  color: #0068B5;
  font-size: 14px;
  text-align: center;
  line-height: 36px;
  border: 1px solid #0068B5;
  cursor: pointer;
  margin-top: 16px;
}

.password-prompt {
  padding-top: 10px;
}

.text-green {
  color: green;
  text-decoration: underline;
}

.check-group {
  font-size: 14px;
  color: #333333;
}

.check-group > textarea {
  width: 100%;
  border: 1px solid #D7D7D7;
  border-radius: 0;
  padding: 12px;
  margin-top: 16px;
}
.check-group > textarea::placeholder {
  color: #333333;
}
.check-button input {
  cursor: pointer;
}
</style>
